package com.cucn.ingmall.search.controller;

import com.cucn.ingmall.search.dto.SearchResponseDTO;
import com.cucn.ingmall.search.service.MallSearchService;
import com.cucn.ingmall.search.vo.SearchRequestParamVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 检索业务-controller跳转
 *
 * @author KouChaoJie
 * @since: 2021/12/28 10:50
 */
@Controller
@Slf4j
public class SearchController {

    @Resource
    MallSearchService mallSearchService;

    /**
     * 检索服务跳转,带数据显示
     *
     * @param searchRequestParamVO 检索的参数
     * @return 跳转到检索结果页(带数据)
     */
    @RequestMapping("/list.html")
    public String listPage(SearchRequestParamVO searchRequestParamVO, Model model, HttpServletRequest httpServletRequest) {

        //url的查询字符串
        String queryString = httpServletRequest.getQueryString();
        searchRequestParamVO.setQueryString(queryString);
        SearchResponseDTO result = mallSearchService.search(searchRequestParamVO);

        log.info("检索出的数据:{}",result);

        model.addAttribute("result", result);

        return "list";
    }
}
